import { createI18n } from "vue-i18n";
const DEFAULT_LANG = "zh";

const importFn = (data) => {
	let lang = {};

	data.keys().forEach(key => {
		const moduleName = key.replace(/^\.\/(.*)\.\w+$/, '$1');
		moduleName && (lang[moduleName] = data(key))
		
	})
	return lang;
};

let locales = {
	en: importFn(
		import.meta.webpackContext("../locales/US-EN/", {
			recursive: false,
			regExp: /\.json$/
		})
	),
	zh: importFn(
		import.meta.webpackContext("../locales/ZH-CN/", {
			recursive: false,
			regExp: /\.json$/
		})
	),
};

const $globalLang = createI18n({
	locale: DEFAULT_LANG,
	messages: locales,
});

export { $globalLang };
